package archimede;

import java.awt.Color;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;

public class PopupRel extends JPopupMenu {
	private Pannello pan;
	private Rel rel;

	public PopupRel(Pannello p, Rel r) {
		this.pan = p;
		this.rel = r;
		setBackground(new Color(234, 234, 234));
		inizializza();
	}

	public void inizializza() {
		JMenuItem nome = new JMenuItem("Nome");
		AbstractAction nomeAction = new AbstractAction("Nome") {
			public void actionPerformed(ActionEvent e) {
				String nm = JOptionPane
						.showInputDialog(null, "Inserisci il nuovo nome.",
								PopupRel.this.rel.getNome());
				if (nm != null) {
					while (!Check.checkString(nm)) {
						Check.showErrorMessage();
						nm = JOptionPane.showInputDialog(null,
								"Inserisci il nuovo nome.", nm);
					}
					if (nm != null)
						PopupRel.this.rel.setNome(nm);
				}
				PopupRel.this.pan.repaint();
			}
		};
		nome.addActionListener(nomeAction);
		nome.setBackground(new Color(234, 234, 234));

		JMenuItem elimina = new JMenuItem("Elimina");
		AbstractAction eliminaAction = new AbstractAction("El") {
			public void actionPerformed(ActionEvent e) {
				int ris = JOptionPane.showConfirmDialog(null,
						"Vuoi eliminare questo punto?");
				if (ris == 0)
					PopupRel.this.rel.eliminami();
			}
		};
		elimina.addActionListener(eliminaAction);
		elimina.setBackground(new Color(234, 234, 234));

		add(nome);

		addSeparator();

		add(elimina);
	}
}